<template>
	<view>
		<view class="user">
			<image src="../../static/img/login-logo.fd503e0.png" mode=""></image>
		</view>
		<u-toast ref="uToast"></u-toast>
		<view>
			<view class="inputBox">
				<view class="" style="display: flex;flex-direction: row;align-items: center;">
					<text style="font-size: 35rpx;font-weight: bold;"> 账号</text>
					<input type="text" v-model="user" placeholder="请输入账号">
				</view>
				<view class="" style="display: flex;flex-direction: row;align-items: center;">
					<text style="font-size: 35rpx;font-weight: bold;"> 密码</text>
					<input v-model="password" type="text" placeholder="请输入密码">
				</view>
				<view class="" style="display: flex;flex-direction: row;align-items: center;">
					<text style="font-size: 35rpx;font-weight: bold;"> 确认密码</text>
					<input v-model="cpaww" type="text" placeholder="请再次输入密码">
				</view>
			</view>
			<view :class="[isSubmit?'isSubmit':'','submit']" @click="submit">
				注册
			</view>

		</view>

		<!-- 登录loading -->
		<u-overlay :show="load">
			<view class="loading">
				<u-loading-icon mode="circle" color="#129369" size="50" text="注册中"></u-loading-icon>
			</view>
		</u-overlay>
	</view>
</template>

<script>
	import {
		register
	} from '@/api/index.js'
	export default {
		data() {
			return {
				user: '',
				password: '',
				cpaww: '',
				isSubmit: false,
				load: false,
			}
		},
		computed: {
			listenChange() {
				const {
					password,
					user,
				} = this
				return {
					password,
					user
				}
			}
		},
		watch: {
			listenChange(newValue) {
				if (this.user != '' && this.password != '' && this.cpaww == this.password) {
					this.isSubmit = true
				} else {
					this.isSubmit = false
				}
			}
		},
		methods: {
			submit() {
				if (this.isSubmit) {
					this.load = true
					register({
						mobile: this.user,
						password: this.password,
						confirm: this.cpaww
					}).then(res => {
						this.load = false
						if (res.status == "error") {
							this.$refs.uToast.show({
								type: 'error',
								duration: '1000',
								position: 'top',
								message: res.msg,
								complete() {

								}
							})
						} else {
							this.load = false
							this.$refs.uToast.show({
								type: 'success',
								position: 'top',
								duration: '1000',
								message: res.msg,
								complete() {
									uni.setStorageSync('utoken', res.data.token)
									uni.redirectTo({
										url: '/pages/login/login'
									})
								}
							})
						}

					})
				} else {
					this.$refs.uToast.show({
						type: 'error',
						position: 'top',
						message: "请完整填写后再提交！",
						complete() {

						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.user {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;

		image {
			margin-top: 100rpx;
			height: 130rpx;
			width: 130rpx;
		}
	}

	.loading {
		height: 100vh;
		display: flex;
		flex-direction: row;
		justify-content: center;
	}

	.inputBox {
		margin-top: 100rpx;
		margin-left: 30rpx;

		view {
			margin-bottom: 50rpx;
		}

		input {
			margin-left: 40rpx;
		}
	}

	.submit {
		background-color: #f1a6ad;
		width: 90%;
		height: 90rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		border-radius: 60rpx;
		margin-top: 150rpx;
		color: #fff;
		font-size: 30rpx;
		font-weight: bold;
		margin: 0 auto;
		margin-top: 90rpx;
	}

	.isSubmit {
		background: #e53c4e !important;
		color: #fff !important;
	}

	.loading {
		height: 100vh;
		display: flex;
		flex-direction: row;
		justify-content: center;
	}
</style>